package com.woniuxy.charin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.woniuxy.charin.mapper.StationFeeStandardMapper;
import com.woniuxy.charin.model.entity.ChargingPile;
import com.woniuxy.charin.model.entity.StationFeeStandard;
import com.woniuxy.charin.service.StationFeeStandardService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务接口实现
 *
 * @author
 * @description
 * @since 2024-12-23 20:41:46
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class StationFeeStandardServiceImpl extends
        ServiceImpl<StationFeeStandardMapper, StationFeeStandard>
        implements StationFeeStandardService {
    @Autowired
    StationFeeStandardMapper stationFeeStandardMapper;

    public List<StationFeeStandard> getStationFeeStandardList(int page, int size) {
        log.info("getChargingPileList: page={}, size={}", page, size);
        Page<StationFeeStandard> stationFeeStandardPage = new Page<>(page, size);
        return stationFeeStandardMapper.selectPage(stationFeeStandardPage, null).getRecords();
    }

    public void addStationFeeStandard(StationFeeStandard stationFeeStandard) {
        log.info("addStationFeeStandard: stationFeeStandard={}", stationFeeStandard);
        stationFeeStandardMapper.insert(stationFeeStandard);
    }

    public void updateStationFeeStandard(StationFeeStandard stationFeeStandard) {
        log.info("updateStationFeeStandard: stationFeeStandard={}", stationFeeStandard);
        stationFeeStandardMapper.updateById(stationFeeStandard);
    }

    @Override
    public List<StationFeeStandard> getStationFeeStandardByStationId(Integer stationId, int page, int size) {
        log.info("getStationFeeStandardByStationId: stationId={} page={}, size={}", page, size, stationId);
        // 创建分页对象
        Page<StationFeeStandard> StationFeeStandardPage = new Page<>(page, size);

        // 使用 LambdaQueryWrapper 拼装查询条件
        LambdaQueryWrapper<StationFeeStandard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StationFeeStandard::getStationId, stationId);
        // 使用分页查询
        Page<StationFeeStandard> resultPage = stationFeeStandardMapper.selectPage(
                StationFeeStandardPage, wrapper);

        // 返回查询到的记录
        return resultPage.getRecords();
    }

    public void deleteStationFeeStandard(int id) {
        log.info("deleteStationFeeStandard: id={}", id);
        stationFeeStandardMapper.deleteById(id);
    }
}